package br.urca.impl;

import java.util.List;

import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.transaction.Transactional;

import br.urca.dao.BiAssuntosDAO;
import br.urca.model.BiAssuntos;

@Transactional
public class JPABiAssuntosDAO implements BiAssuntosDAO {
	
	private EntityManager manager;
	
	public JPABiAssuntosDAO() {
		this(null);
	}
	
	@Inject
	public JPABiAssuntosDAO(EntityManager manager) {
		this.manager = manager;
	}
	
	@Override
	public BiAssuntos getPorId(Short codAssunto) {
		return this.manager
				.createQuery(
						"SELECT b FROM BiAssuntos b where b.codAssunto = :codigo",
						BiAssuntos.class).setParameter("codigo", codAssunto)
				.getSingleResult();
	}

	@Override
	public List<BiAssuntos> getPorDescricao(String descricao) {
		return this.manager
				.createQuery(
						"SELECT b FROM BiAssuntos b WHERE b.descricao LIKE '%" + descricao + "%'",
						BiAssuntos.class)
				.getResultList();
	}

}
